package org.biodas.jdas.client;


import java.io.IOException;

import org.biodas.jdas.exceptions.DASClientException;
import org.biodas.jdas.schema.stylesheet.DASSTYLE;

import javax.xml.bind.JAXBException;

/**
 * Created by IntelliJ IDEA.
 * User: ljgarcia
 * Date: 11-Apr-2011
 * Time: 16:40:58
 * To change this template use File | Settings | File Templates.
 */
public class StyleSheetClient {

	   ConnectionPropertyProviderI connectionProps = null;
	 
	   public StyleSheetClient()
	   {
	   }
	 
	   public StyleSheetClient(ConnectionPropertyProviderI connProps) {
	     this.connectionProps = connProps;
	   }

    /**
     * Retrieves the sources for a data source.
     * @return
     * @throws java.net.MalformedURLException
     * @throws javax.xml.bind.JAXBException
     */
    public DASSTYLE fetchData(String serverURL) throws DASClientException {
		try {
            String url;
            if (!serverURL.endsWith("/")) {
                url = serverURL + "/stylesheet";
            } else {
                url = serverURL + "stylesheet";
            }
            NoDtdJaxbParser parser=new NoDtdJaxbParser();
            return (DASSTYLE)parser.parseXmlUrl(url,"org.biodas.jdas.schema.stylesheet", connectionProps);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			throw new DASClientException(e.getMessage(), e.getCause());
		
		} catch (JAXBException e) {
			throw new DASClientException(e.getMessage(), e.getCause());
	    }
    }
}
